home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / challenge / 11.11 / 11.11ProgrammersChall.sit.hqx / 11.11 Challenge Text next >
Text File  |  1995-10-25  |  2KB  |  20 lines

  1. Enclosing Bounds
  2.  
  3. The Challenge this month is based on a suggestion by Mike Scanlin, who remains a fan of the column.  (We’re still waiting for Mike’s first Challenge entry, however.) The problem is to write a routine that will return a rectangle enclosing all non-white pixels in a selected area of an image.  This code might be useful in a drawing or painting program, where the user would be allowed to select a subset of the image by clicking and dragging, and the software would select all of the elements of the image contained within that selection.  The prototype of the code you will write is:
  4.  
  5. void EnclosingBounds(
  6.     PixMapHandle pm,             /* handle to PixMap containing image */
  7.     Rect selection,             /* subset of image to enclose */
  8.     Rect *enclosingRect        /* enclosing rect return value */
  9. );
  10.  
  11. Your code should examine all of the pixels within the selection rectangle of the PixMap and return the smallest rectangle containing all of the non-white pixels.  Pixels outside the selection rectangle should be ignored.  The bounds rectangle of the PixMap will be no larger than 2048 pixels in each dimension, the baseAddr pointer will be longword aligned, and rowBytes will be a multiple of 4.  You should deal with pixelSize values of 1, 8, or 32, with values of 8 and 32 being weighted most heavily in measuring performance.  For PixMaps with indexed pixels (cmpCount==1), the color table will contain white as the first table entry (as all good color tables are supposed to).  For PixMaps with direct pixels, the unused (alpha) bits of each pixel will be zero.
  12.  
  13. You may use either the Metrowerks or the Symantec compilers for this native PowerPC Challenge.  If you have any questions, or would like some test data for your code, please send me e-mail at one of the Programmer’s Challenge addresses, or directly to boonstra@ultranet.com.
  14.  
  15. __________________________
  16. This is the text of an article orginially printed in MacTech Magazine™.  MacTech Magazine, for Macintosh Programmers and Developers.  For subscription information, please contact us at:
  17.   •  http://www.mactech.com
  18.   •  mailto:info@mactech.com
  19.   •  805/494-9797
  20.